#ifndef _PACKET_PARSER_H_
#define _PACKET_PARSER_H_

#include "Define.h"
#include "IPacketParser.h"

#define _IDENTIFY_VER    0x05
#define _ENCODE_NONE     0x00
#define _MESSAGE_VER     0x03
class CODPacketParser : public SGLib::IPacketParser
{
public:

    struct tagHeader
    {
        unsigned char  identity;
        unsigned char  encode;
        unsigned short length;
        unsigned char  version;
        unsigned char  reserve;
        unsigned short type;
    };

    s32 GetHeadLen()
    {
        return sizeof(struct tagHeader);
    }
    s32 GetPacketLen(const byte *data)
    {
        tagHeader *header = (tagHeader*)data;
        return ntohs(header->length);
    }
    void FillHeader(byte *data, s32 len, u32 type)
    {
        tagHeader *header = (tagHeader*)data;
        header->identity = _IDENTIFY_VER;
        header->encode = _ENCODE_NONE;
        header->length = htons(len);
        header->version = _MESSAGE_VER;
        header->type = htons((u16)type);
    }
    u32 GetMsgId(const byte *data)
    {
        tagHeader *header = (tagHeader*)data;
        return ntohs(header->type);
    }
};

#endif

